<?php
    //  收货地址编辑，添加页面
    require_once "config.php";
    require_once "weixin_info.php";
    require_once "jssdk.php";
    $id = empty($_GET['id']) ? '' : $_GET['id'];
    if(!empty($id)){
        $add_sql = $mysql->query("select * from dyspw_mem_address where  id = {$id} ");
        $add_info = $add_sql->fetch_all(MYSQLI_ASSOC);
    }
 ?>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <meta name="viewport"
          content="width=device-width, initial-scale=1.0, user-scalable=0, minimum-scale=1.0, maximum-scale=1.0">
    <title>管理管理员/导购员</title>
    <script src="js/mui.min.js"></script>
    <link href="css/mui.min.css" rel="stylesheet" />
    <link href="css/index.css" rel="stylesheet" />
    <link rel="stylesheet" href="css/core.css">
    <script src="https://a.amap.com/jsapi_demos/static/demo-center/js/demoutils.js"></script>
    <script type="text/javascript" src="https://webapi.amap.com/maps?v=1.4.15&key=d021bae86db1d54dddc4071a5123749c&plugin=AMap.Geocoder"></script>
    <style>
        .mui-input-row input::placeholder {
            font-size: 12px;
            letter-spacing: 1px;
            color: #999 !important;
        }
        .mui-input-row input::-webkit-input-placeholder {
            font-size: 12px;
            letter-spacing: 1px;
            color: #999 !important;
        }
        .mui-input-row input::-ms-input-placeholder {
            font-size: 12px;
            letter-spacing: 1px;
            color: #999 !important;
        }
        .mui-input-row input::-moz-placeholder {
            font-size: 12px;
            letter-spacing: 1px;
            color: #999 !important;
        }
        .actio{background: #8d97b2 !important;color: #fff;}
    </style>

    <script src="https://cdn.bootcss.com/vConsole/3.2.0/vconsole.min.js"></script>
<script>
let vConsole = new VConsole();
</script>
</head>
<body>
    <section class="address-edit-box">
        <header id="header" class="mui-bar mui-bar-nav">
            <a class="mui-action-back mui-icon mui-icon-left-nav mui-pull-left"></a>
            <h1 id="editAddressTittle" class="mui-title">管理管理员/导购员</h1>
        </header>
        <form id="addressEditForm" class="mui-input-group">
            <div class="mui-input-row">
                <label> <i style="color: red;">*</i> 联系人</label>
                <input id="person" type="text" class="mui-input-clear"  placeholder="请输入用户手机号">
            </div>
            <div class="mui-input-row">
                <label> <i style="color: red;">*</i> 身份</label>
                <div class="">
                    <span class="identity" identity="run" style="margin-top: 7px;display: inline-block;width: 90px;text-align: center;line-height: 30px;    background: #ccc;border-radius: 5px;font-size: 12px;">管理员店铺</span>
                    <span class="identity" identity="guide" style="margin-top: 7px;display: inline-block;width: 90px;text-align: center;line-height: 30px;    background: #ccc;border-radius: 5px;font-size: 12px;">店铺导购员</span>
                </div>
            </div>
            <div class="mui-button-row" style="padding: 5px 15px;">
                <a id="addressEdit" class="addressEditBtn" href="javascript:void(0);">保存并使用</a>
            </div>
            <div id="wrapper" style="display:none;"></div>
        </form>
    </section>
</body>
<script src="js/jquery-2.2.4.min.js" type="text/javascript"></script>
 <script type="text/javascript">
 $(function() {
     $(".identity").click(function(){
         $(this).parent().find('.identity').removeClass('actio');
         $(this).addClass("actio");
     })
     $('#addressEdit').click(function () {
        var check = true;
        var identity = $('.identity').parent().find(".actio").attr("identity");
        console.log(identity);
        if(identity == '' || identity == undefined ){
            mui.alert("身份信息不允许为空");
            check = false;
            return false;
        }
        mui("#addressEditForm .mui-input-clear").each(function() {
            //若当前input为空，则alert提醒
            if(!this.value || this.value.trim() == "") {
                var label = this.previousElementSibling;
                mui.alert(label.innerText + "不允许为空");
                check = false;
                return false;
            }
        }); //校验通过，继续执行业务逻辑
        if(check){

            var person = $('#person').val();
            var uid = '<?php echo $_SESSION['Member_info'][0]['id']; ?>';
            $.ajax({
                url: 'mem_run_ajax.php',
                type: "post",
                data: {'username':person,'uid':uid,'identity':identity} ,
                dataType: 'json',
                success:function(res){
                    console.log(res);
                    if(res.status == 'y'){
                        mui.alert(res.info);
                        if(res.identity == 'guide'){
                            window.location.href = "./member_guide.php";
                        }else if(res.identity == 'run'){
                            window.location.href = "./member_run.php";
                        }
                    }else{
                        mui.alert(res.info);
                    }
                }
            })
        }
     })
 })
 </script>
</html>
